package com.neusoft.neuiotms.dcom.util;

import com.neusoft.bizcore.auth.common.bean.UserBean;
import com.neusoft.neuiotms.dcom.constants.DCOMConstants;

public class PermUtils {
    public static boolean isWorker(UserBean bean) {
        return bean.getRoles().stream().filter(it -> DCOMConstants.ROLE_WORKER.equals(it.getRole())).findAny()
                .isPresent();
    }

    public static boolean isWorkerGroupLeader(UserBean bean) {
        return bean.getRoles().stream().filter(it -> DCOMConstants.ROLE_WORKER_GROUP_LEADER.equals(it.getRole()))
                .findAny()
                .isPresent();
    }

    public static boolean isExport(UserBean bean) {
        return bean.getRoles().stream().filter(it -> DCOMConstants.ROLE_EXPERT.equals(it.getRole()))
                .findAny()
                .isPresent();
    }

    public static boolean isExpertGroupLeader(UserBean bean) {
        return bean.getRoles().stream().filter(it -> DCOMConstants.ROLE_EXPERT_GROUP_LEADER.equals(it.getRole()))
                .findAny()
                .isPresent();
    }

    public static boolean isBackup(UserBean bean) {
        return bean.getRoles().stream().filter(it -> DCOMConstants.ROLE_BACKUP.equals(it.getRole()))
                .findAny()
                .isPresent();
    }

    public static boolean isZongjian(UserBean bean) {
        return bean.getRoles().stream().filter(it -> DCOMConstants.ROLE_ZONGJIAN.equals(it.getRole()))
                .findAny()
                .isPresent();
    }

    public static boolean isAdmin(UserBean bean) {
        return bean.getRoles().stream().filter(it -> DCOMConstants.ROLE_ADMIN.equals(it.getRole()))
                .findAny()
                .isPresent();
    }

    public static boolean isWorkerOrWorkerGroupLeader(UserBean bean) {
        return PermUtils.isWorker(bean) || PermUtils.isWorkerGroupLeader(bean);
    }

    public static boolean isBigdataBureau(UserBean bean) {
        return bean.getRoles().stream().filter(it -> DCOMConstants.ROLE_BIGDATA_BUREAU.equals(it.getRole())).findAny()
                .isPresent();
    }
}
